-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix comparison from wrong formats with datetime objects #2697
Conversation
…id the exception "TypeError: can't compare offset-naive and offset-aware datetimes" with Python 3.11
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2697 +/- ##
=============================================
+ Coverage 88.607% 88.661% +0.054%
=============================================
Files 87 87
Lines 6820 6844 +24
Branches 1171 1178 +7
=============================================
+ Hits 6043 6068 +25
Misses 535 535
+ Partials 242 241 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
Any update on this? |
Hi there, looks good. Can you please add a test to prevent a regression? |
This is my first time contributing to Sanic, could you please show me how to add test? |
Sure. Sanic uses pytest for testing (you can find guides for that online) and you can run the tests on your own machine by
Or alternatively directly with Since your patch is in sanic/request/, the appropriate test file is probably that mentioned in the example above. It might already have a test function that tests the When doing bugfixes and tests for them, it is a good practice to then try running your test without your patch, to see that it actually fails, and then apply the patch and see that it passes. Please ask if you have any further questions, we'll be happy to help getting started with that! |
@stricaud Hey, how are you doing? Let me know if you need help with the test. |
I am trying to write the test, however it has been many days and I don't see how to reproduce this problem. |
@stricaud I think I see what you are after. Do you mind if I make some pushes to your branch? |
I don't mind! Very welcome |
I'd like to make sure that the fix proposed is the right one: what causes tz-aware and unaware timestamps being mixed here, can we make both either tz-aware or not aware? If not, is there a chance that one of them would be in local tz, and produce wrong timestamp value? |
Yup. I am not sure how best to avoid this without going too deep and over-engineering this. My vote is as the implementation I pushed: handle when they are both aware and both naive. If there is a mismatch, add the missing tz as UTC and throw up a warning. |
Make sure datetime objects are used in their timestamp format to avoid the exception "TypeError: can't compare offset-naive and offset-aware datetime" with Python 3.11